package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.shop.bean.app.dto.UserLikeRecordDto;
import com.yami.shop.bean.model.UserLikeRecord;
import com.yami.shop.dao.UserLikeRecordMapper;
import com.yami.shop.service.UserLikeRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户喜欢记录 服务实现类
 * </p>
 *
 * @author chajiu
 * @since 2021-06-29
 */
@Service
public class UserLikeRecordServiceImpl extends ServiceImpl<UserLikeRecordMapper, UserLikeRecord> implements UserLikeRecordService {
    @Autowired
    private UserLikeRecordMapper userLikeRecordMapper;

    @Override
    public List<UserLikeRecordDto> getLikeListByUserId(String uid) {
        return userLikeRecordMapper.getLikeListByUserId(uid);
    }

    @Override
    public boolean isLiked(String fromId, String toId) {

        //是否已喜欢该用户
        int count1 = count(Wrappers.lambdaQuery(new UserLikeRecord())
                .eq(UserLikeRecord::getFromUserId, fromId)
                .eq(UserLikeRecord::getLikeUserId, toId));
        if (count1 > 0) {
            return true;
        } else {
            return false;
        }

    }
}
